import { h } from 'vue'
import { ComponentMap } from '../config/index'

export function renderComponent(componentList) {
  return componentList.map((item) => {
    if (!ComponentMap[item.name]) return null

    const { children, ...resetProps } = item.props || {}

    let child = () => children || ''

    if (item.children && item.children.length) {
      child = renderComponent(item?.children ?? [])
    }

    return h(ComponentMap[item.name], { ...resetProps }, child)
  })
}
